package dolphin.mt521.cam.ac.uk;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.app.Activity;
import android.content.Intent;

public class MainActivity extends Activity {

    ImageView iv;
    static int count = 1;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        iv = (ImageView) findViewById(R.id.status);
        iv.setImageResource(R.drawable.none);
        
        //Decode (full chunks)
        Button decode = (Button) findViewById(R.id.decode);
        decode.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                iv.setImageResource(R.drawable.waiting);
                Dolphin.decode();
                iv.setImageResource(R.drawable.done);
                count++;
            }
        });
        
      //Decode (half chunks)
        Button decode2 = (Button) findViewById(R.id.decode2);
        decode2.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                iv.setImageResource(R.drawable.waiting);
                Dolphin.decodeHalf();
                iv.setImageResource(R.drawable.done);
                count++;
            }
        });
        
        //Encode
        Button encode = (Button) findViewById(R.id.encode);
        encode.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                iv.setImageResource(R.drawable.waiting);
                Dolphin.encodePreset();
                iv.setImageResource(R.drawable.done);
            }
        });
        
        //Reset
        Button reset = (Button) findViewById(R.id.reset);
        final MainActivity thisClass = this;
        reset.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                Intent i = new Intent(thisClass,MainActivity.class);
                thisClass.startActivity(i);
                thisClass.finish();
            }
        });
    }

}
